﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllDistributorByIdDataAction : BestLifeDataAction<List<Distributor>>
    {
        private string GvDisId;

        public BestLifeGetAllDistributorByIdDataAction(string PDisId)
        {
            GvDisId = PDisId;
        }

        public override List<Distributor> Body(SqlConnection PConn)
        {
            try
            {
                List<Distributor> LvList = new List<Distributor>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetDistributorById";
                LvCommand.Parameters.Add(new SqlParameter("@DisID", GvDisId));

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Distributor LvDistributor = new Distributor();
                    LvDistributor.Dis_ID = LvReader.GetValue(0).ToString();
                    LvDistributor.Giv_Name = LvReader.GetValue(3).ToString();
                    //LvSubCategory.Description = LvReader.GetValue(4).ToString();
                    //LvSubCategory.Status = LvReader.GetValue(5).ToString();

                    LvList.Add(LvDistributor);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
